﻿/**
 * - 男女双方均为未婚
 * - 男方必须年满 22 周岁，女方必须年满 20 周岁
 * - 结婚的双方必须是男女异性 ( 现行中国法律不支持同性结婚 )
 *
 * 根据以上内容，要求在 marry 方法内部根据中国现行法律的结婚条件，来判断自己是否可以根另外一个人结婚:
 *
 * - 如果可以结婚，则提示 自己 可以 和 某某 结婚
 * - 如果不满足结婚条件，则提示不能结婚的原因
 */
public class Person {
    //field
    public String name;
    public char gender;
    public int age;
    public boolean married;

    public void marry(Person another){
        // 在这里填空，判断自己 ( this ) 跟 另外一个人( another )结婚
        boolean result;
        if (this.married == false && another.married == false)
        {
            if (this.gender == '男' && another.gender == '女'){
                if (this.age >= 22 && another.age >=20){
                    System.out.println(this.name + " 和 " + another.name + " 可以结婚");
                }else {
                    System.out.println(this.name + " 和 " + another.name + "不能结婚，因为男方未满22岁或女方未满20岁");
                }
            }else if ( this.gender == '女' && another.gender == '男'){
                if (this.age >= 20 && another.age >=22){
                    System.out.println(this.name + " 和 " + another.name + " 可以结婚");
                } else {
                    System.out.println(this.name + " 和 " + another.name + "不能结婚，因为男方未满22岁或女方未满20岁");
                }
            } else {
                System.out.println(this.name + " 和 " + another.name + "不能结婚，因为不是异性");
            }
        }else {
            System.out.println(this.name + " 和 " + another.name + "不能结婚，因为有人已婚，所以不能结婚");
        }
    }

    public static void main(String[] args) {
        Person first = new Person();
        first.name = "蒋嘉豪";
        first.gender = '男';
        first.age = 21;
        first.married = false;

        Person second = new Person();
        second.name = "胡耀文";
        second.gender = '女';
        second.age = 23;
        second.married = false;

        Person third = new Person();
        third.name = "张三丰";
        third.gender = '男';
        third.age = 35;
        third.married = false;

        Person fourth = new Person();
        fourth.name = "宝儿姐";
        fourth.gender = '女';
        fourth.age = 20;
        fourth.married = true;

        first.marry(second);
        first.marry(third);
        first.marry(fourth);

        second.marry(third);
        second.marry(fourth);
    }
}
